﻿#include "configView.h"
#include "Common.h"


configView::configView(QString strConfigPath, QDialog*parent)
	: QDialog(parent)
{
	ui.setupUi(this);
	m_strConfigPath = strConfigPath;

	m_runPath = QCoreApplication::applicationDirPath();
}

configView::~configView()
{
}


void configView::showValue()
{
	ui.lineEdit_sys_1->setText(g_strSaveImageDir);
	ui.lineEdit_sys_2->setText(g_strReleaseImageDir);



	QFileInfo info1(m_strShellDetModelPath);
	ui.lineEdit_1->setText(info1.fileName());

	QFileInfo info2(m_strShellRectDefectModelPath);
	ui.lineEdit_2->setText(info2.fileName());


	QFileInfo info2_1(m_strShellRectClassModelPath);
	ui.lineEdit_2_1->setText(info2_1.fileName());

	QFileInfo info3(m_strKettleDetModelPath);
	ui.lineEdit_3->setText(info3.fileName());

	QFileInfo info4(m_strKettleRectDefectModelPath);
	ui.lineEdit_4->setText(info4.fileName());

	QFileInfo info5(m_strRQ_SteelDetModelPath);
	ui.lineEdit_5->setText(info5.fileName());

	QFileInfo info6(m_strRQ_MotorDetModelPath);
	ui.lineEdit_6->setText(info6.fileName());

	QFileInfo info7(m_strRQ_FloorDetModelPath);
	ui.lineEdit_7->setText(info7.fileName());
	
	QFileInfo info8(m_strJX_SteelDetModelPath);
	ui.lineEdit_8->setText(info8.fileName());

	QFileInfo info0_11(m_strJX_CableDetModelPath);
	ui.lineEdit_0_11->setText(info0_11.fileName());

	QFileInfo info9(m_strFrameDetModelPath);
	ui.lineEdit_9->setText(info9.fileName());

	QFileInfo info10(m_strTopDetModelPath);
	ui.lineEdit_10->setText(info10.fileName());

	QFileInfo info23(m_strTopRectDefectModelPath);
	ui.lineEdit_23->setText(info23.fileName());

	QFileInfo info23_1(m_strTopRectClassModelPath);
	ui.lineEdit_23_1->setText(info23_1.fileName());

	QFileInfo info26(m_strJX_SteelRectDefectModelPath);
	ui.lineEdit_26->setText(info26.fileName());


	QFileInfo info28(m_strRQ_MotorRectDefectModelPath);
	ui.lineEdit_28->setText(info28.fileName());
	QFileInfo info28_1(m_strRQ_MotorRectClassModelPath);
	ui.lineEdit_28_1->setText(info28_1.fileName());

	QFileInfo info29(m_strRQ_FloorRectDefectModelPath);
	ui.lineEdit_29->setText(info29.fileName());
	QFileInfo info30(m_strRQ_SteelRectDefectModelPath);
	ui.lineEdit_30->setText(info30.fileName());
	
}

void configView::on_btnOK_clicked()
{
	ConfigUtils::setCfgStr(m_strConfigPath, "Config", "SaveImageDir", g_strSaveImageDir);
	ConfigUtils::setCfgStr(m_strConfigPath, "Config", "ReleaseImageDir", g_strReleaseImageDir);



	ConfigUtils::setCfgStr(m_strConfigPath, "Config", "ShellDetModelPath", m_strShellDetModelPath);
	ConfigUtils::setCfgStr(m_strConfigPath, "Config", "ShellRectDefectModelPath", m_strShellRectDefectModelPath);
	ConfigUtils::setCfgStr(m_strConfigPath, "Config", "ShellRectClassModelPath", m_strShellRectClassModelPath);

	ConfigUtils::setCfgStr(m_strConfigPath, "Config", "KettleDetModelPath", m_strKettleDetModelPath);
	ConfigUtils::setCfgStr(m_strConfigPath, "Config", "KettleRectDefectModelPath", m_strKettleRectDefectModelPath);

	ConfigUtils::setCfgStr(m_strConfigPath, "Config", "RQ_SteelDetModelPath", m_strRQ_SteelDetModelPath);
	ConfigUtils::setCfgStr(m_strConfigPath, "Config", "RQ_MotorDetModelPath", m_strRQ_MotorDetModelPath);
	ConfigUtils::setCfgStr(m_strConfigPath, "Config", "RQ_FloorDetModelPath", m_strRQ_FloorDetModelPath);

	ConfigUtils::setCfgStr(m_strConfigPath, "Config", "JX_CableDetModelPath", m_strJX_CableDetModelPath);
	ConfigUtils::setCfgStr(m_strConfigPath, "Config", "JX_SteelDetModelPath", m_strJX_SteelDetModelPath);

	ConfigUtils::setCfgStr(m_strConfigPath, "Config", "JX_SteelRectDefectModelPath", m_strJX_SteelRectDefectModelPath);

	ConfigUtils::setCfgStr(m_strConfigPath, "Config", "FrameDetModelPath", m_strFrameDetModelPath);

	ConfigUtils::setCfgStr(m_strConfigPath, "Config", "TopDetModelPath", m_strTopDetModelPath);
	ConfigUtils::setCfgStr(m_strConfigPath, "Config", "TopRectDefectModelPath", m_strTopRectDefectModelPath);
	ConfigUtils::setCfgStr(m_strConfigPath, "Config", "TopRectClassModelPath", m_strTopRectClassModelPath);

	ConfigUtils::setCfgStr(m_strConfigPath, "Config", "RQ_MotorRectDefectModelPath", m_strRQ_MotorRectDefectModelPath);
	ConfigUtils::setCfgStr(m_strConfigPath, "Config", "RQ_FloorRectDefectModelPath", m_strRQ_FloorRectDefectModelPath);
	ConfigUtils::setCfgStr(m_strConfigPath, "Config", "RQ_SteelRectDefectModelPath", m_strRQ_SteelRectDefectModelPath);
	ConfigUtils::setCfgStr(m_strConfigPath, "Config", "RQ_MotorRectClassModelPath", m_strRQ_MotorRectClassModelPath);


	this->close();
}


void configView::on_btnCancel_clicked()
{
	this->close();
}


void configView::on_brnChange_sys_1_clicked()
{
	QString m_strFilePath = g_strSaveImageDir;
	QString directory = QFileDialog::getExistingDirectory(this, "Save Image File", m_strFilePath);
	if (!directory.isEmpty())
	{
		g_strSaveImageDir = directory;
		ui.lineEdit_sys_1->setText(g_strSaveImageDir);
	}


}

void configView::on_brnChange_sys_2_clicked()
{
	QString m_strFilePath = g_strReleaseImageDir;
	QString directory = QFileDialog::getExistingDirectory(this, "Save Release File", m_strFilePath);
	if (!directory.isEmpty())
	{
		g_strReleaseImageDir = directory;
		ui.lineEdit_sys_2->setText(g_strReleaseImageDir);
	}
}

void configView::on_brnChange1_clicked()
{
	QString OpenFile;
	OpenFile = QFileDialog::getOpenFileName(this,
		"请打开蒙皮定位模型", "",
		"Image Files(*.detnet);;All(*.*)");
	if (!OpenFile.isEmpty())
	{
		QFileInfo info(OpenFile);

		QString strNewFileName = m_runPath + "//model//" + info.dir().dirName() + "//" + info.fileName();
		DirExistEx(strNewFileName);
		QFile::copy(OpenFile, strNewFileName);
		info.setFile(strNewFileName);

		m_strShellDetModelPath = strNewFileName;
		ui.lineEdit_1->setText(info.fileName());
	}
}

void configView::on_brnChange2_clicked()
{
	QString OpenFile;
	OpenFile = QFileDialog::getOpenFileName(this,
		"请打开蒙皮缺陷检测模型", "",
		"Image Files(*.detnet);;All(*.*)");
	if (!OpenFile.isEmpty())
	{
		QFileInfo info(OpenFile);

		QString strNewFileName = m_runPath + "//model//" + info.dir().dirName() + "//" + info.fileName();
		DirExistEx(strNewFileName);
		QFile::copy(OpenFile, strNewFileName);
		info.setFile(strNewFileName);

		m_strShellRectDefectModelPath = strNewFileName;
		ui.lineEdit_2->setText(info.fileName());
	}
}

void configView::on_brnChange2_1_clicked()
{
	QString OpenFile;
	OpenFile = QFileDialog::getOpenFileName(this,
		"请打开蒙皮缺陷分类模型", "",
		"Image Files(*.clsnet);;All(*.*)");
	if (!OpenFile.isEmpty())
	{
		QFileInfo info(OpenFile);

		QString strNewFileName = m_runPath + "//model//" + info.dir().dirName() + "//" + info.fileName();
		DirExistEx(strNewFileName);
		QFile::copy(OpenFile, strNewFileName);
		info.setFile(strNewFileName);

		m_strShellRectClassModelPath = strNewFileName;
		ui.lineEdit_2_1->setText(info.fileName());
	}
}


void configView::on_brnChange3_clicked()
{
	QString OpenFile;
	OpenFile = QFileDialog::getOpenFileName(this,
		"请打开水壶定位模型", "",
		"Image Files(*.detnet);;All(*.*)");
	if (!OpenFile.isEmpty())
	{
		QFileInfo info(OpenFile);

		QString strNewFileName = m_runPath + "//model//" + info.dir().dirName() + "//" + info.fileName();
		DirExistEx(strNewFileName);
		QFile::copy(OpenFile, strNewFileName);
		info.setFile(strNewFileName);

		m_strKettleDetModelPath = strNewFileName;
		ui.lineEdit_3->setText(info.fileName());
	}
}

void configView::on_brnChange4_clicked()
{
	QString OpenFile;
	OpenFile = QFileDialog::getOpenFileName(this,
		"请打开水壶缺陷检测模型", "",
		"Image Files(*.clsnet);;All(*.*)");
	if (!OpenFile.isEmpty())
	{
		QFileInfo info(OpenFile);

		QString strNewFileName = m_runPath + "//model//" + info.dir().dirName() + "//" + info.fileName();
		DirExistEx(strNewFileName);
		QFile::copy(OpenFile, strNewFileName);
		info.setFile(strNewFileName);

		m_strKettleRectDefectModelPath = strNewFileName;
		ui.lineEdit_4->setText(info.fileName());
	}
}

void configView::on_brnChange5_clicked()
{
	QString OpenFile;
	OpenFile = QFileDialog::getOpenFileName(this,
		"请打开融青钢索定位模型", "",
		"Image Files(*.detnet);;All(*.*)");
	if (!OpenFile.isEmpty())
	{
		QFileInfo info(OpenFile);

		QString strNewFileName = m_runPath + "//model//" + info.dir().dirName() + "//" + info.fileName();
		DirExistEx(strNewFileName);
		QFile::copy(OpenFile, strNewFileName);
		info.setFile(strNewFileName);

		m_strRQ_SteelDetModelPath = strNewFileName;
		ui.lineEdit_5->setText(info.fileName());
	}
}

void configView::on_brnChange6_clicked()
{
	QString OpenFile;
	OpenFile = QFileDialog::getOpenFileName(this,
		"请打开融青电机定位模型", "",
		"Image Files(*.detnet);;All(*.*)");
	if (!OpenFile.isEmpty())
	{
		QFileInfo info(OpenFile);

		QString strNewFileName = m_runPath + "//model//" + info.dir().dirName() + "//" + info.fileName();
		DirExistEx(strNewFileName);
		QFile::copy(OpenFile, strNewFileName);
		info.setFile(strNewFileName);

		m_strRQ_MotorDetModelPath = strNewFileName;
		ui.lineEdit_6->setText(info.fileName());
	}
}

void configView::on_brnChange7_clicked()
{
	QString OpenFile;
	OpenFile = QFileDialog::getOpenFileName(this,
		"请打开融青地板定位模型", "",
		"Image Files(*.detnet);;All(*.*)");
	if (!OpenFile.isEmpty())
	{
		QFileInfo info(OpenFile);

		QString strNewFileName = m_runPath + "//model//" + info.dir().dirName() + "//" + info.fileName();
		DirExistEx(strNewFileName);
		QFile::copy(OpenFile, strNewFileName);
		info.setFile(strNewFileName);

		m_strRQ_FloorDetModelPath = strNewFileName;
		ui.lineEdit_7->setText(info.fileName());
	}
}

void configView::on_brnChange8_clicked()
{
	QString OpenFile;
	OpenFile = QFileDialog::getOpenFileName(this,
		"请打开久行电缆定位模型", "",
		"Image Files(*.detnet);;All(*.*)");
	if (!OpenFile.isEmpty())
	{
		QFileInfo info(OpenFile);

		QString strNewFileName = m_runPath + "//model//" + info.dir().dirName() + "//" + info.fileName();
		DirExistEx(strNewFileName);
		QFile::copy(OpenFile, strNewFileName);
		info.setFile(strNewFileName);


		m_strJX_SteelDetModelPath = strNewFileName;
		ui.lineEdit_8->setText(info.fileName());
	}
}


void configView::on_brnChange11_clicked()
{
	QString OpenFile;
	OpenFile = QFileDialog::getOpenFileName(this,
		"请打开玖行钢索定位模型", "",
		"Image Files(*.detnet);;All(*.*)");
	if (!OpenFile.isEmpty())
	{
		QFileInfo info(OpenFile);

		QString strNewFileName = m_runPath + "//model//" + info.dir().dirName() + "//" + info.fileName();
		DirExistEx(strNewFileName);
		QFile::copy(OpenFile, strNewFileName);
		info.setFile(strNewFileName);

		m_strJX_CableDetModelPath = strNewFileName;
		ui.lineEdit_0_11->setText(info.fileName());
	}
}


void configView::on_brnChange9_clicked()
{
	QString OpenFile;
	OpenFile = QFileDialog::getOpenFileName(this,
		"请打开电池框架定位模型", "",
		"Image Files(*.detnet);;All(*.*)");
	if (!OpenFile.isEmpty())
	{
		QFileInfo info(OpenFile);

		QString strNewFileName = m_runPath + "//model//" + info.dir().dirName() + "//" + info.fileName();
		DirExistEx(strNewFileName);
		QFile::copy(OpenFile, strNewFileName);
		info.setFile(strNewFileName);

		m_strFrameDetModelPath = strNewFileName;
		ui.lineEdit_9->setText(info.fileName());
	}
}

void configView::on_brnChange10_clicked()
{
	QString OpenFile;
	OpenFile = QFileDialog::getOpenFileName(this,
		"请打开电池顶部定位模型", "",
		"Image Files(*.detnet);;All(*.*)");
	if (!OpenFile.isEmpty())
	{
		QFileInfo info(OpenFile);

		QString strNewFileName = m_runPath + "//model//" + info.dir().dirName() + "//" + info.fileName();
		DirExistEx(strNewFileName);
		QFile::copy(OpenFile, strNewFileName);
		info.setFile(strNewFileName);
	

		m_strTopDetModelPath = strNewFileName;
		ui.lineEdit_10->setText(info.fileName());
	}
}



void configView::on_brnChange21_clicked()
{

}
void configView::on_brnChange22_clicked()
{

}
void configView::on_brnChange23_clicked()
{
	QString OpenFile;
	OpenFile = QFileDialog::getOpenFileName(this,
		"请打开电池顶部定位模型", "",
		"Image Files(*.detnet);;All(*.*)");
	if (!OpenFile.isEmpty())
	{
		QFileInfo info(OpenFile);

		QString strNewFileName = m_runPath + "//model//" + info.dir().dirName() + "//" + info.fileName();
		DirExistEx(strNewFileName);
		QFile::copy(OpenFile, strNewFileName);
		info.setFile(strNewFileName);


		m_strTopRectDefectModelPath = strNewFileName;
		ui.lineEdit_23->setText(info.fileName());
	}
}

void configView::on_brnChange23_1_clicked()
{
	QString OpenFile;
	OpenFile = QFileDialog::getOpenFileName(this,
		"请打开电池顶部缺陷分类模型", "",
		"Image Files(*.clsnet);;All(*.*)");
	if (!OpenFile.isEmpty())
	{
		QFileInfo info(OpenFile);

		QString strNewFileName = m_runPath + "//model//" + info.dir().dirName() + "//" + info.fileName();
		DirExistEx(strNewFileName);
		QFile::copy(OpenFile, strNewFileName);
		info.setFile(strNewFileName);


		m_strTopRectClassModelPath = strNewFileName;
		ui.lineEdit_23_1->setText(info.fileName());
	}
}


void configView::on_brnChange24_clicked()
{

}
void configView::on_brnChange25_clicked()
{

}


void configView::on_brnChange26_clicked()
{
	QString OpenFile;
	OpenFile = QFileDialog::getOpenFileName(this,
		"请打开钢丝缺陷检测模型", "",
		"Image Files(*.detnet);;All(*.*)");
	if (!OpenFile.isEmpty())
	{
		QFileInfo info(OpenFile);

		QString strNewFileName = m_runPath + "//model//" + info.dir().dirName() + "//" + info.fileName();
		DirExistEx(strNewFileName);
		QFile::copy(OpenFile, strNewFileName);
		info.setFile(strNewFileName);


		m_strJX_SteelRectDefectModelPath = strNewFileName;
		ui.lineEdit_26->setText(info.fileName());
	}
}


void configView::on_brnChange27_clicked()
{

}


void configView::on_brnChange28_clicked()
{
	QString OpenFile;
	OpenFile = QFileDialog::getOpenFileName(this,
		"请打开融青电机漏油检测模型", "",
		"Image Files(*.detnet);;All(*.*)");
	if (!OpenFile.isEmpty())
	{
		QFileInfo info(OpenFile);

		QString strNewFileName = m_runPath + "//model//" + info.dir().dirName() + "//" + info.fileName();
		DirExistEx(strNewFileName);
		QFile::copy(OpenFile, strNewFileName);
		info.setFile(strNewFileName);

		m_strRQ_MotorRectDefectModelPath = strNewFileName;
		ui.lineEdit_28->setText(info.fileName());
	}
}


void configView::on_brnChange28_1_clicked()
{
	QString OpenFile;
	OpenFile = QFileDialog::getOpenFileName(this,
		"请打开融青电机漏油分类模型", "",
		"Image Files(*.clsnet);;All(*.*)");
	if (!OpenFile.isEmpty())
	{
		QFileInfo info(OpenFile);

		QString strNewFileName = m_runPath + "//model//" + info.dir().dirName() + "//" + info.fileName();
		DirExistEx(strNewFileName);
		QFile::copy(OpenFile, strNewFileName);
		info.setFile(strNewFileName);

		m_strRQ_MotorRectClassModelPath = strNewFileName;
		ui.lineEdit_28_1->setText(info.fileName());
	}
}

void configView::on_brnChange29_clicked()
{
	QString OpenFile;
	OpenFile = QFileDialog::getOpenFileName(this,
		"请打开融青钢丝断股检测模型", "",
		"Image Files(*.detnet);;All(*.*)");
	if (!OpenFile.isEmpty())
	{
		QFileInfo info(OpenFile);

		QString strNewFileName = m_runPath + "//model//" + info.dir().dirName() + "//" + info.fileName();
		DirExistEx(strNewFileName);
		QFile::copy(OpenFile, strNewFileName);
		info.setFile(strNewFileName);


		m_strRQ_FloorRectDefectModelPath = strNewFileName;
		ui.lineEdit_29->setText(info.fileName());
	}
	
}
void configView::on_brnChange30_clicked()
{
	QString OpenFile;
	OpenFile = QFileDialog::getOpenFileName(this,
		"请打开融青钢丝断股检测模型", "",
		"Image Files(*.detnet);;All(*.*)");
	if (!OpenFile.isEmpty())
	{
		QFileInfo info(OpenFile);

		QString strNewFileName = m_runPath + "//model//" + info.dir().dirName() + "//" + info.fileName();
		DirExistEx(strNewFileName);
		QFile::copy(OpenFile, strNewFileName);
		info.setFile(strNewFileName);


		m_strRQ_SteelRectDefectModelPath = strNewFileName;
		ui.lineEdit_30->setText(info.fileName());
	}
}